<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>申请休假</title>
	
	<link href="/oas/css/style.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
		.avDiv{margin:5px;}
		.avSubmit{text-align:center;}
		.avForm{margin-left:256px;}
		.check{color:red;}
		.avTextarea{width:70%}
	</style>
	
	<script type="text/javascript" src="/oas/js/Calendar4.js"></script>
	
	<script type="text/javascript" >
		function checkInput()
		{
			var nowTime=new Date();
			var startTime=document.getElementById("startTime").value;
			var startYear=startTime.slice(0,4);
			var startMonth=startTime.slice(5,7);
			var startDay=startTime.slice(8,10);
			var startDate=new Date();
			startDate.setFullYear(startYear,startMonth-1,startDay)
			if(nowTime.getTime()>=startDate.getTime())
			{
				alert("申请休假：开始时间必须从明天开始！");
				document.getElementById("startTime").focus();
				return false;
			}
			
			var endTime=document.getElementById("endTime").value;
			var endYear=endTime.slice(0,4);
			var endMonth=endTime.slice(5,7);
			var endDay=endTime.slice(8,10);
			var endDate=new Date();
			endDate.setFullYear(endYear,endMonth-1,endDay);
			if(startDate.getTime()>endDate.getTime())
			{
				alert("申请休假：结束时间必须晚于开始时间！");
				document.getElementById("endTime").focus();
				return false;
			}
			
			var d=endDay-startDay+1;
			var days=document.getElementById("days");
			with(days)
			{
				if(isNaN(value))
				{
					alert("申请休假:申请天数必须为数字！");
					focus();
					return false;
				}
				if(value==null || value=="")
				{
					alert("申请休假：申请天数必须填写！");
					focus();
					return false;
				}
				if(value<1 || value.indexOf(".")>-1)
				{
					alert("申请休假：申请天数必须为正整数！");
					focus();
					return false;
				}
				if(value!=d)
				{
					alert("申请天数跟日期时间不符");
					focus();
					return false;
				}
			}
			return true;
		}
	</script>
	
</head>
<body>
	<div class="action">
		<div class="t">
			申请休假
		</div>
		<div class="pages">
			<form class="avForm" action="/oas/vacation/submit" onsubmit="return checkInput()" method="post">
				<div class="avDiv"><span>&nbsp;&nbsp;&nbsp;&nbsp;姓名：<input type="text" name="username"/></span></div>
				<div class="avDiv"><span>开始时间：<input type="text" name="vacation.startTime" id="startTime" onclick="MyCalendar.SetDate(this)"/></span><span class="check">*</span></div>
				<div class="avDiv"><span>结束时间：<input type="text" name="vacation.endTime" id="endTime" onclick="MyCalendar.SetDate(this)"/></span><span class="check">*</span></div>
				<div class="avDiv">
					<span>请假天数：<input type="text" name="vacation.days" id="days"/></span>
					<span class="check">*</span>
					<span>(天数=结束时间-开始时间+1)</span>
				</div>
				<div class="avDiv"><span>请假原因：</span><textarea name="vacation.reason" class="avTextarea"></textarea></div>
				<div class="avDiv">
					<span>&nbsp;审批人：</span>
					<select name="vacation.approver.workNo">
						<s:iterator value="#request.managers" status="mStatus" id="manager">
							<option value="<s:property value='#manager.workNo'/>"><s:property value="#manager.username"/></option>
						</s:iterator>
					</select>
				</div>
				<div class="avSubmit">
					<input type="submit" value="提交申请"/>
					&nbsp;&nbsp;
					<a href="/oas/vacation/index">返回</a>
				</div>
			</form>
				
		</div>
	</div>
</body>
</html>